import os


def getAllImage(folderPath, imageList, newPath):
    extend_name = ["jpg", "jpeg", "png", "bmp"]
    for item in os.listdir(folderPath):
        if os.path.isdir(os.path.join(folderPath, item)):
            subFolderPath = os.path.join(folderPath, item)
            newFolderPath = subFolderPath.replace(folderPath,newPath)
            if not os.path.exists(newFolderPath):
                os.mkdir(path)
            getAllImage(subFolderPath, imageList)
        else:

            filePath = os.path.join(folderPath, item)
            if os.path.isfile(filePath):
                if item.split('.')[-1] in extend_name:
                    imageList.append(filePath)
    return imageList


if __name__ == '__main__':
    path = "E:\实验室数据集"
    newPath = "E:\实验室数据集\去光数据集"
    imageList = []
    imageList = getAllImage(path, imageList)
    print(imageList)
